
var video = {
    add : function(){
        if ( check() ){
            $.ajax({
                url : 'http://house.wechatpic.com/Admin/Data/add_video_c',
                type : "post",
                data : {
                    program : $(".program").val(),
                    loupan : $(".loupan").val(),
                    time : $('#time').val(),
                    url : $('.url').val()
                },
                dataType : 'json',
                success : function(data){
                    console.log(data);
                    if (data.msg == 0 ){
                    	alert('新增成功')
                        window.location.href='http://house.wechatpic.com/Data/video_list?v=4.0'
                    }else{
                    	alert('新增失败')
                    }
                }
            })            
        }
    },
    time : function(time){
    		
        $.ajax({
            url : 'http://house.wechatpic.com/Admin/Data/get_active_by_time',
            type : 'post',
            data : {
                time : time
            },
            dataType : 'json',
            success : function(data){
                var html1 = template('program', data);
                $(".program").html(html1);
                video.getFloor($('#time').val(),$('.program').val())
            }
        })
    },
    getFloor : function(time,program){
    		$.ajax({
    			url : 'http://house.wechatpic.com/Admin/Data/get_loupan_by_time_and_active',
    			type : 'post',
    			data : {
    				time : time,
    				program : program
    			},
    			dataType : 'json',
    			success : function(data){
    				var floorHtml = template('loupan',data)
    				$(".loupan").html(floorHtml)
    			}
    		})
    },
    edit : function(){
        $.ajax({
            url : 'http://house.wechatpic.com/Admin/Data/edit_video_c',
            type : "post",
            data : {
                v_id : $("#v_id").val(),
                program : $(".program").val(),
                loupan : $(".loupan").val(),
                time : $('#time').val(),
                url : $('.url').val()
            },
            dataType : 'json',
            success : function(data){
                console.log(data);
                if (data.msg == 0 ){
                    alert('修改成功')
                    window.location.href='http://house.wechatpic.com/Data/video_list?v=4.0'
                }else{
                    alert("修改失败")
                }
            }
        })              
    }
}

$('#time').datetimepicker({
    language:  'fr',
    weekStart: 1,
    todayBtn:  1,
    autoclose: 1,
    todayHighlight: 1,
    startView: 2,
    minView: 2,
    forceParse: 0
}).on('changeDate',function(ev){
    video.time($('#time').val())
})

$(".program").on('change',function(){
	video.getFloor($('#time').val(),$('.program').val())
})

function check(){
    var program = $('.program').val();
    if(program == '0'){
        alert('请选择项目名称');return false;
    }
    var loupan = $('.loupan').val();
    if(loupan == '0'){
        alert('请选择楼盘名称');return false;
    }
    var url = $('.url').val();
    if(url == ''){
        alert('请输入对接视频地址');return false;
    }
    return true
}
